﻿using ConfExpert.Forms.Base;
using ConfExpert.Utility;
using DevTeam;
using System;
using System.Data;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo.Aksesuar
{
    public partial class AksVendor : XForm
    {
        BindingSource bs;
        public AksVendor(string tip)
        {
            InitializeComponent();

            switch (tip)
            {
                case "AksVendor":
                    this.Text = "Üreticiler";
                    txtInfo.Caption = "Aksesuar Üreticileri";
                    TAM.VendorTableAdapter = new ConfExpert.Datasets.MyDataTableAdapters.VendorTableAdapter();
                    TAM.VendorTableAdapter.Fill(ds.Vendor);
                    bs = new BindingSource(ds, "Vendor");
                    bs.Filter = "StokTipiId = 2";
                    ds.Vendor.TableNewRow += new DataTableNewRowEventHandler(Vendor_TableNewRow);
                    break;
            }
        }

        private void AksVendor_Load(object sender, EventArgs e)
        {            
            try
            {
                AddBsToList(bs);
                InitGridView(gvOverview, bs);
                gvOverview.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;

                bs.CurrentChanged += new EventHandler(bs_CurrentChanged);
                btnKaydet.ItemClick += btnKaydet_ItemClick;
                gvOverview.BestFitColumns();
            }
            catch (Exception ex)
            {
                ShowMessage(ex);
            }
        }

        void Vendor_TableNewRow(object sender, DataTableNewRowEventArgs e)
        {
            e.Row["StokTipiId"] = 2;
        }


        void bs_CurrentChanged(object sender, EventArgs e)
        {
            txtInfo.Caption = ((DataRowView)bs.Current).Row["Name"].ToString();
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvOverview.EndEditing();
            Save();
            GetDetails("Vendor", "UpdCariByTip", "V");

            AppSession.MainForm.RefreshData();
        }
    }
}